<?php
/**
 * Created by PhpStorm.
 * User: Dick
 * Date: 2016/3/28
 * Time: 0:29
 */

namespace Controller;

use Method\Template;
use Model\Picture;
use Method\Response;
use Model\User;

class Settings
{
    public function index()
    {
        include Template::load('Other/settings');
    }

    public static function uploadzl()
    {
        $zl = new User();
        $zl->id = $_SESSION['user']->id;
        $zl->nickname = $_POST['screen-name'];
        $zl->personal = $_POST['personal'];
        $zl->uploadzl();
        Response::redirect('Settings');
    }

    public static function uploadzh()
    {
        $zh = new User();
        $zh->id = $_SESSION['user']->id;
        $zh->username = $_POST['username'];
        $zh->email = $_POST['user-email'];
        $zh->uploadzh();
        Response::redirect('Settings');
    }

    public static function uploadmm()
    {
        $mm = new User();
        $mm->id = $_SESSION['user']->id;
        $mm->savePassword($_POST['userpassword']);
        Response::redirect('Settings');
    }

    public static function uploadtx()
    {
        $userid = $_SESSION['user']->id;
        $file = $_POST['imgsend'];
        if (!$file) {
            return;
        }
        $sendpic = new Picture();
        $sendpic->uploadtx($userid, $file);
        Response::redirect('Settings');
    }

    public static function uploadbg()
    {
        $userid = $_SESSION['user']->id;
        $file = $_POST['bgsend'];
        if (!$file) {
            return;
        }
        $sendpic = new Picture();
        $sendpic->uploadbg($userid, $file);
        Response::redirect('Settings');
    }

    /**
     * 测重
     * */
    public function verifyname()
    {
        $name = $_POST['name'];
        User::verifyname($name);
    }

    public function verifyemail()
    {
        $email = $_POST['email'];
        User::verifyemail($email);
    }

    public function verifypassword()
    {
        $mm = User::GetUserById($_SESSION['user']->id);
        if ($mm->verifyPassword($_POST['pwd'])) {
            echo 1;
        } else {
            echo 0;
        }

    }
}